********************************************************************************
**  TITLE:      us2004_naes_contact_networks                                  **  
**  AUTHOR:	    Philippe Mongrain                                             **
**  DATA:       DataNRCS                                                      **
**  DATE:	    October 2022 						                          **	
**  VERSION:	Stata 16					                                  **	
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "us2004_naes_contact_networks", replace

* Open the dataset

use "DataNRCS.dta", clear


***************************
** INDEPENDENT VARIABLES **
***************************

* Time (presidential election)

gen surveydate=date(string(cdate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY surveydate

gen edate = 20041102

gen electiondate=date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

gen time = electiondate - surveydate

* Time (Democratic primary election)

gen ddate = 20040729

gen demdate=date(string(ddate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY demdate

gen dtime = demdate - surveydate

* Gender

gen male = cwa01

recode male (2=0)

* Age

gen age = cwa02

recode age (998=.)
recode age (999=.)

replace age = . if age < 17

* Education

gen education = cwa03

recode education (998=.)
recode education (999=.)

* Interest for politics/election

gen followpolitics = cka01
gen followcampaign = cka04
gen interestcampaign = cka05

recode followpolitics (998=.)
recode followpolitics (999=.)
recode followpolitics (4=3)

recode followcampaign (998=.)
recode followcampaign (999=.)
recode followcampaign (4=3)

recode interestcampaign (998=.)
recode interestcampaign (999=.)

gen interest_president = .

replace interest_president = followpolitics
replace interest_president = followcampaign if followcampaign!=.
replace interest_president = interestcampaign if interestcampaign!=.

replace interest_president = 4 - interest_president

gen interest_primaries = .

replace interest_primaries = followpolitics
replace interest_primaries = followcampaign if followcampaign!=.

replace interest_primaries = 4 - interest_primaries

* Party identification

gen pidstatus_whole = cma01

recode pidstatus_whole (4=3)
recode pidstatus_whole (998=.)
recode pidstatus_whole (999=.)

replace pidstatus_whole = 30 if pidstatus_whole == 1
replace pidstatus_whole = 20 if pidstatus_whole == 3
replace pidstatus_whole = 10 if pidstatus_whole == 2

replace pidstatus_whole = 1 if pidstatus_whole == 10
replace pidstatus_whole = 2 if pidstatus_whole == 20
replace pidstatus_whole = 3 if pidstatus_whole == 30

label define pidstatus 1 "Loser PID" 2 "No PID/Other" 3 "Winner PID" 
label values pidstatus_whole pidstatus

* Party identification scale

gen pidscale_whole = .

replace pidscale_whole = 1 if pidstatus_whole == 1 & cma02 == 1
replace pidscale_whole = 2 if pidstatus_whole == 1 & cma02 == 2
replace pidscale_whole = 3 if cma03 == 2
replace pidscale_whole = 4 if pidstatus_whole == 2 & cma03 == 3 | pidstatus_whole == 2 & cma03 == 998
replace pidscale_whole = 5 if cma03 == 1
replace pidscale_whole = 6 if pidstatus_whole == 3 & cma02 == 2
replace pidscale_whole = 7 if pidstatus_whole == 3 & cma02 == 1

label define pidscale 1 "Strong loser PID" 2 "Moderate loser PID" 3 "Weak loser PID" 4 "No PID/Other" 5 "Weak winner PID" 6 "Moderate winner PID" 7 "Strong winner PID" 
label values pidscale_whole pidscale

* Evaluation of Kerry

gen kerryrating = cab01

recode kerryrating (11=.)
recode kerryrating (12=.)
recode kerryrating (999=.)

* Evaluation of Clark

gen clarkrating = cac17

recode clarkrating (11=.)
recode clarkrating (12=.)
recode clarkrating (999=.)

* Evaluation of Dean

gen deanrating = cac26

recode deanrating (11=.)
recode deanrating (12=.)
recode deanrating (999=.)

* Evaluation of Edwards

gen edwardsrating = cac26

recode edwardsrating (11=.)
recode edwardsrating (12=.)
recode edwardsrating (999=.)

* Evaluation of Gephardt

gen gephardtrating = cac35

recode gephardtrating (11=.)
recode gephardtrating (12=.)
recode gephardtrating (999=.)

* Evaluation of Lieberman

gen liebermanrating = cac44

recode liebermanrating (11=.)
recode liebermanrating (12=.)
recode liebermanrating (999=.)

* Democratic primary preference

gen demprefA = kerryrating 
gen demprefB = clarkrating  
gen demprefC = deanrating 
gen demprefD = edwardsrating 
gen demprefE = gephardtrating 
gen demprefF = liebermanrating 

gen dempref_complete = 1 if demprefA!=. & demprefB!=. & demprefC!=. & demprefD!=. & demprefE!=. & demprefF!=.

gen dempreference = 3 if demprefA >= demprefB & demprefA >= demprefC & demprefA >= demprefD & demprefA >= demprefE & demprefA >= demprefF & dempref_complete == 1
replace dempreference = 2 if demprefA == demprefB & demprefA == demprefC & demprefA == demprefD & demprefA == demprefE & demprefA == demprefF & dempref_complete == 1
replace dempreference = 1 if dempreference!=2 & dempreference!=3 & dempref_complete == 1

replace dempreference = . if dempreference == 3 & demprefA == demprefB & dempref_complete == 1
replace dempreference = . if dempreference == 3 & demprefA == demprefC & dempref_complete == 1
replace dempreference = . if dempreference == 3 & demprefA == demprefD & dempref_complete == 1
replace dempreference = . if dempreference == 3 & demprefA == demprefE & dempref_complete == 1
replace dempreference = . if dempreference == 3 & demprefA == demprefF & dempref_complete == 1

label define dempreference 1 "Loser Democratic preference" 2 "No preference" 3 "Winner Democratic preference"
label values dempreference dempreference

* National TV news attentiveness

gen nattv = cea05

recode nattv (998=.)
recode nattv (999=.)

replace nattv = 5 - nattv

recode nattv (.=-99)

* Local TV news attentiveness

gen loctv = cea07

recode loctv (998=.)
recode loctv (999=.)

replace loctv = 5 - loctv

recode loctv (.=-99)

* Press news attentiveness

gen press = cea13

recode press (998=.)
recode press (999=.)

replace press = 5 - press

recode press (.=-99)

* News attentiveness index

egen news = rowmax(nattv loctv press)

recode news (-99=.)

* Political discussion

gen discussion_family_friends = ckb01

recode discussion_family_friends (998=.)
recode discussion_family_friends (999=.)

gen discussion_work = ckb03

recode discussion_work (998=.)
recode discussion_work (999=.)

gen discussion_online = ckb05

recode discussion_online (998=.)
recode discussion_online (999=.)

replace discussion_online = 0 if cea21 == 2 | cea21 == 998

gen discussion = discussion_family_friends + discussion_work + discussion_online

gen discussion_family_friends_3pts = 0 if discussion_family_friends < 2 & discussion_family_friends!=.
replace discussion_family_friends_3pts = 1 if discussion_family_friends >= 2 & discussion_family_friends < 4 & discussion_family_friends!=.
replace discussion_family_friends_3pts = 2 if discussion_family_friends >= 4 & discussion_family_friends!=.

gen discussion_work_3pts = 0 if discussion_work < 2 & discussion_work!=.
replace discussion_work_3pts = 1 if discussion_work >= 2 & discussion_work < 4 & discussion_work!=.
replace discussion_work_3pts = 2 if discussion_work >= 4 & discussion_work!=.

gen discussion_online_3pts = 0 if discussion_online < 2 & discussion_online!=.
replace discussion_online_3pts = 1 if discussion_online >= 2 & discussion_online < 4 & discussion_online!=.
replace discussion_online_3pts = 2 if discussion_online >= 4 & discussion_online!=.

egen discussion_3pts = rowmax(discussion_family_friends_3pts discussion_work_3pts discussion_online_3pts)


***************************************
** DEMOCRATIC PRIMARIES EXPECTATIONS **
***************************************

* Generate variable identifying incomplete answers

gen clarkprimaries = cna01
gen deanprimaries = cna02
gen edwardsprimaries = cna03
gen gephardtprimaries = cna04
gen kerryprimaries = cna05
gen liebermanprimaries = cna06

gen complete_demprimaries_1 = 1 if clarkprimaries!=. & deanprimaries!=. & edwardsprimaries!=. & gephardtprimaries!=. & kerryprimaries!=. & liebermanprimaries!=. & electiondate <= date("20040119","YMD")
gen complete_demprimaries_2 = 1 if clarkprimaries!=. & deanprimaries!=. & edwardsprimaries!=. & kerryprimaries!=. & liebermanprimaries!=. & electiondate > date("20040119","YMD") & electiondate <= date("20040210","YMD")
gen complete_demprimaries_3 = 1 if deanprimaries!=. & edwardsprimaries!=. & kerryprimaries!=. & liebermanprimaries!=. & electiondate > date("20040210","YMD") & electiondate <= date("20040217","YMD")
gen complete_demprimaries_4 = 1 if edwardsprimaries!=. & kerryprimaries!=. & liebermanprimaries!=. & electiondate > date("20040217","YMD")

* Generate value of 1 if the expectation for one candidate is higher or equal to the expectations for at least one other candidate

gen demprimariesA = 1 if clarkprimaries >= deanprimaries & clarkprimaries >= edwardsprimaries & clarkprimaries >= gephardtprimaries & clarkprimaries >= kerryprimaries & clarkprimaries >= liebermanprimaries & complete_demprimaries_1 == 1
gen demprimariesB = 1 if deanprimaries >= clarkprimaries & deanprimaries >= edwardsprimaries & deanprimaries >= gephardtprimaries & deanprimaries >= kerryprimaries & deanprimaries >= liebermanprimaries & complete_demprimaries_1 == 1
gen demprimariesC = 1 if edwardsprimaries >= clarkprimaries & edwardsprimaries >= deanprimaries & edwardsprimaries >= gephardtprimaries & edwardsprimaries >= kerryprimaries & edwardsprimaries >= liebermanprimaries & complete_demprimaries_1 == 1
gen demprimariesD = 1 if gephardtprimaries >= clarkprimaries & gephardtprimaries >= deanprimaries & gephardtprimaries >= edwardsprimaries & gephardtprimaries >= kerryprimaries & gephardtprimaries >= liebermanprimaries & complete_demprimaries_1 == 1
gen demprimariesE = 1 if kerryprimaries >= clarkprimaries & kerryprimaries >= deanprimaries & kerryprimaries >= edwardsprimaries & kerryprimaries >= gephardtprimaries & kerryprimaries >= liebermanprimaries & complete_demprimaries_1 == 1
gen demprimariesF = 1 if liebermanprimaries >= clarkprimaries & liebermanprimaries >= deanprimaries & liebermanprimaries >= edwardsprimaries & liebermanprimaries >= gephardtprimaries & liebermanprimaries >= kerryprimaries & complete_demprimaries_1 == 1
gen demprimariesOTH = 1 if clarkprimaries == 0 & deanprimaries == 0 & edwardsprimaries == 0 & gephardtprimaries == 0 & kerryprimaries == 0 & liebermanprimaries == 0 & complete_demprimaries_1 == 1

replace demprimariesA = . if demprimariesOTH == 1 & complete_demprimaries_1 == 1
replace demprimariesB = . if demprimariesOTH == 1 & complete_demprimaries_1 == 1
replace demprimariesC = . if demprimariesOTH == 1 & complete_demprimaries_1 == 1
replace demprimariesD = . if demprimariesOTH == 1 & complete_demprimaries_1 == 1
replace demprimariesE = . if demprimariesOTH == 1 & complete_demprimaries_1 == 1
replace demprimariesF = . if demprimariesOTH == 1 & complete_demprimaries_1 == 1

replace demprimariesA = 1 if clarkprimaries >= deanprimaries & clarkprimaries >= edwardsprimaries & clarkprimaries >= kerryprimaries & clarkprimaries >= liebermanprimaries & complete_demprimaries_2 == 1
replace demprimariesB = 1 if deanprimaries >= clarkprimaries & deanprimaries >= edwardsprimaries & deanprimaries >= kerryprimaries & deanprimaries >= liebermanprimaries & complete_demprimaries_2 == 1
replace demprimariesC = 1 if edwardsprimaries >= clarkprimaries & edwardsprimaries >= deanprimaries & edwardsprimaries >= kerryprimaries & edwardsprimaries >= liebermanprimaries & complete_demprimaries_2 == 1
replace demprimariesE = 1 if kerryprimaries >= clarkprimaries & kerryprimaries >= deanprimaries & kerryprimaries >= edwardsprimaries & kerryprimaries >= liebermanprimaries & complete_demprimaries_2 == 1
replace demprimariesF = 1 if liebermanprimaries >= clarkprimaries & liebermanprimaries >= deanprimaries & liebermanprimaries >= edwardsprimaries & liebermanprimaries >= kerryprimaries & complete_demprimaries_2 == 1
replace demprimariesOTH = 1 if clarkprimaries == 0 & deanprimaries == 0 & edwardsprimaries == 0 & kerryprimaries == 0 & liebermanprimaries == 0 & complete_demprimaries_2 == 1

replace demprimariesA = . if demprimariesOTH == 1 & complete_demprimaries_2 == 1
replace demprimariesB = . if demprimariesOTH == 1 & complete_demprimaries_2 == 1
replace demprimariesC = . if demprimariesOTH == 1 & complete_demprimaries_2 == 1
replace demprimariesE = . if demprimariesOTH == 1 & complete_demprimaries_2 == 1
replace demprimariesF = . if demprimariesOTH == 1 & complete_demprimaries_2 == 1

replace demprimariesB = 1 if deanprimaries >= edwardsprimaries & deanprimaries >= kerryprimaries & deanprimaries >= liebermanprimaries & complete_demprimaries_3 == 1
replace demprimariesC = 1 if edwardsprimaries >= deanprimaries & edwardsprimaries >= kerryprimaries & edwardsprimaries >= liebermanprimaries & complete_demprimaries_3 == 1
replace demprimariesE = 1 if kerryprimaries >= deanprimaries & kerryprimaries >= edwardsprimaries & kerryprimaries >= liebermanprimaries & complete_demprimaries_3 == 1
replace demprimariesE = 1 if liebermanprimaries >= deanprimaries & liebermanprimaries >= edwardsprimaries & liebermanprimaries >= kerryprimaries & complete_demprimaries_3 == 1
replace demprimariesOTH = 1 if deanprimaries == 0 & edwardsprimaries == 0 & kerryprimaries == 0 & liebermanprimaries == 0 & complete_demprimaries_3 == 1

replace demprimariesB = . if demprimariesOTH == 1 & complete_demprimaries_3 == 1
replace demprimariesC = . if demprimariesOTH == 1 & complete_demprimaries_3 == 1
replace demprimariesE = . if demprimariesOTH == 1 & complete_demprimaries_3 == 1
replace demprimariesF = . if demprimariesOTH == 1 & complete_demprimaries_3 == 1

replace demprimariesC = 1 if edwardsprimaries >= kerryprimaries & edwardsprimaries >= liebermanprimaries & complete_demprimaries_4 == 1
replace demprimariesE = 1 if kerryprimaries >= edwardsprimaries & kerryprimaries >= liebermanprimaries & complete_demprimaries_4 == 1
replace demprimariesE = 1 if liebermanprimaries >= edwardsprimaries & liebermanprimaries >= kerryprimaries & complete_demprimaries_4 == 1
replace demprimariesOTH = 1 if edwardsprimaries == 0 & kerryprimaries == 0 & liebermanprimaries == 0 & complete_demprimaries_4 == 1

replace demprimariesC = . if demprimariesOTH == 1 & complete_demprimaries_4 == 1
replace demprimariesE = . if demprimariesOTH == 1 & complete_demprimaries_4 == 1
replace demprimariesF = . if demprimariesOTH == 1 & complete_demprimaries_4 == 1

* Generate variable for ambiguous forecasts

gen ambiguous_demprimaries = .

replace ambiguous_demprimaries = 99 if demprimariesA == demprimariesB & demprimariesA!=. | demprimariesA == demprimariesC & demprimariesA!=. | demprimariesA == demprimariesD & demprimariesA!=. | demprimariesA == demprimariesE & demprimariesA!=. | demprimariesA == demprimariesF & demprimariesA!=.
replace ambiguous_demprimaries = 99 if demprimariesB == demprimariesA & demprimariesB!=. | demprimariesB == demprimariesC & demprimariesB!=. | demprimariesB == demprimariesD & demprimariesB!=. | demprimariesB == demprimariesE & demprimariesB!=. | demprimariesB == demprimariesF & demprimariesB!=.
replace ambiguous_demprimaries = 99 if demprimariesC == demprimariesA & demprimariesC!=. | demprimariesC == demprimariesB & demprimariesC!=. | demprimariesC == demprimariesD & demprimariesC!=. | demprimariesC == demprimariesE & demprimariesC!=. | demprimariesC == demprimariesF & demprimariesC!=.
replace ambiguous_demprimaries = 99 if demprimariesD == demprimariesA & demprimariesD!=. | demprimariesD == demprimariesB & demprimariesD!=. | demprimariesD == demprimariesC & demprimariesD!=. | demprimariesD == demprimariesE & demprimariesD!=. | demprimariesD == demprimariesF & demprimariesD!=.
replace ambiguous_demprimaries = 99 if demprimariesE == demprimariesA & demprimariesE!=. | demprimariesE == demprimariesB & demprimariesE!=. | demprimariesE == demprimariesC & demprimariesE!=. | demprimariesE == demprimariesD & demprimariesE!=. | demprimariesE == demprimariesF & demprimariesE!=.
replace ambiguous_demprimaries = 99 if demprimariesF == demprimariesA & demprimariesF!=. | demprimariesF == demprimariesB & demprimariesF!=. | demprimariesF == demprimariesC & demprimariesF!=. | demprimariesF == demprimariesD & demprimariesF!=. | demprimariesF == demprimariesE & demprimariesF!=.

* Generate value of 0 for lower expectations

replace demprimariesA = 0 if demprimariesA!=1 & demprimariesA!=. & complete_demprimaries_1 == 1
replace demprimariesB = 0 if demprimariesB!=1 & demprimariesB!=. & complete_demprimaries_1 == 1
replace demprimariesC = 0 if demprimariesC!=1 & demprimariesC!=. & complete_demprimaries_1 == 1
replace demprimariesD = 0 if demprimariesD!=1 & demprimariesD!=. & complete_demprimaries_1 == 1
replace demprimariesE = 0 if demprimariesE!=1 & demprimariesE!=. & complete_demprimaries_1 == 1
replace demprimariesF = 0 if demprimariesF!=1 & demprimariesF!=. & complete_demprimaries_1 == 1
replace demprimariesOTH = 0 if demprimariesOTH!=1 & demprimariesOTH!=. & complete_demprimaries_1 == 1

replace demprimariesA = 0 if demprimariesA!=1 & demprimariesA!=. & complete_demprimaries_2 == 1
replace demprimariesB = 0 if demprimariesB!=1 & demprimariesB!=. & complete_demprimaries_2 == 1
replace demprimariesC = 0 if demprimariesC!=1 & demprimariesC!=. & complete_demprimaries_2 == 1
replace demprimariesE = 0 if demprimariesE!=1 & demprimariesE!=. & complete_demprimaries_2 == 1
replace demprimariesF = 0 if demprimariesF!=1 & demprimariesF!=. & complete_demprimaries_2 == 1
replace demprimariesOTH = 0 if demprimariesOTH!=1 & demprimariesOTH!=. & complete_demprimaries_2 == 1

replace demprimariesB = 0 if demprimariesB!=1 & demprimariesB!=. & complete_demprimaries_3 == 1
replace demprimariesC = 0 if demprimariesC!=1 & demprimariesC!=. & complete_demprimaries_3 == 1
replace demprimariesE = 0 if demprimariesE!=1 & demprimariesE!=. & complete_demprimaries_3 == 1
replace demprimariesF = 0 if demprimariesF!=1 & demprimariesF!=. & complete_demprimaries_3 == 1
replace demprimariesOTH = 0 if demprimariesOTH!=1 & demprimariesOTH!=. & complete_demprimaries_3 == 1

replace demprimariesC = 0 if demprimariesC!=1 & demprimariesC!=. & complete_demprimaries_4 == 1
replace demprimariesE = 0 if demprimariesE!=1 & demprimariesE!=. & complete_demprimaries_4 == 1
replace demprimariesF = 0 if demprimariesF!=1 & demprimariesF!=. & complete_demprimaries_4 == 1
replace demprimariesOTH = 0 if demprimariesOTH!=1 & demprimariesOTH!=. & complete_demprimaries_4 == 1

* Forecasts (1 = Clark, 2 = Dean, 3 = Edwards, 3 = Gephardt, 5 = Kerry, 6 = Lieberman, 88 = other, 99 = ambiguous)

gen forecast_demprimaries = .

replace forecast_demprimaries = 1 if demprimariesA == 1 & complete_demprimaries_1 == 1
replace forecast_demprimaries = 2 if demprimariesB == 1 & complete_demprimaries_1 == 1
replace forecast_demprimaries = 3 if demprimariesC == 1 & complete_demprimaries_1 == 1
replace forecast_demprimaries = 4 if demprimariesD == 1 & complete_demprimaries_1 == 1
replace forecast_demprimaries = 5 if demprimariesE == 1 & complete_demprimaries_1 == 1
replace forecast_demprimaries = 6 if demprimariesF == 1 & complete_demprimaries_1 == 1
replace forecast_demprimaries = 88 if demprimariesOTH == 1 & complete_demprimaries_1 == 1
replace forecast_demprimaries = 99 if ambiguous_demprimaries == 1 & complete_demprimaries_1 == 1

replace forecast_demprimaries = 1 if demprimariesA == 1 & complete_demprimaries_2 == 1
replace forecast_demprimaries = 2 if demprimariesB == 1 & complete_demprimaries_2 == 1
replace forecast_demprimaries = 3 if demprimariesC == 1 & complete_demprimaries_2 == 1
replace forecast_demprimaries = 5 if demprimariesE == 1 & complete_demprimaries_2 == 1
replace forecast_demprimaries = 6 if demprimariesF == 1 & complete_demprimaries_2 == 1
replace forecast_demprimaries = 88 if demprimariesOTH == 1 & complete_demprimaries_2 == 1
replace forecast_demprimaries = 99 if ambiguous_demprimaries == 1 & complete_demprimaries_2 == 1

replace forecast_demprimaries = 2 if demprimariesB == 1 & complete_demprimaries_3 == 1
replace forecast_demprimaries = 3 if demprimariesC == 1 & complete_demprimaries_3 == 1
replace forecast_demprimaries = 5 if demprimariesE == 1 & complete_demprimaries_3 == 1
replace forecast_demprimaries = 6 if demprimariesF == 1 & complete_demprimaries_3 == 1
replace forecast_demprimaries = 88 if demprimariesOTH == 1 & complete_demprimaries_3 == 1
replace forecast_demprimaries = 99 if ambiguous_demprimaries == 1 & complete_demprimaries_3 == 1

replace forecast_demprimaries = 3 if demprimariesC == 1 & complete_demprimaries_4 == 1
replace forecast_demprimaries = 5 if demprimariesE == 1 & complete_demprimaries_4 == 1
replace forecast_demprimaries = 6 if demprimariesF == 1 & complete_demprimaries_4 == 1
replace forecast_demprimaries = 88 if demprimariesOTH == 1 & complete_demprimaries_4 == 1
replace forecast_demprimaries = 99 if ambiguous_demprimaries == 1 & complete_demprimaries_4 == 1

* Identify correct and ambiguous forecasts

gen correct_demprimaries = 0 if forecast_demprimaries!=5 & forecast_demprimaries!=. & complete_demprimaries_1 == 1
replace correct_demprimaries = 1 if forecast_demprimaries == 5 & complete_demprimaries_1 == 1

replace correct_demprimaries = 0 if forecast_demprimaries!=5 & forecast_demprimaries!=. & complete_demprimaries_2 == 1
replace correct_demprimaries = 1 if forecast_demprimaries == 5 & complete_demprimaries_2 == 1

replace correct_demprimaries = 0 if forecast_demprimaries!=5 & forecast_demprimaries!=. & complete_demprimaries_3 == 1
replace correct_demprimaries = 1 if forecast_demprimaries == 5 & complete_demprimaries_3 == 1

replace correct_demprimaries = 0 if forecast_demprimaries!=5 & forecast_demprimaries!=. & complete_demprimaries_4 == 1
replace correct_demprimaries = 1 if forecast_demprimaries == 5 & complete_demprimaries_4 == 1

replace correct_demprimaries = 99 if forecast_demprimaries == 99 & demprimariesE == 1 & complete_demprimaries_1 == 1

replace correct_demprimaries = 99 if forecast_demprimaries == 99 & demprimariesE == 1 & complete_demprimaries_2 == 1

replace correct_demprimaries = 99 if forecast_demprimaries == 99 & demprimariesE == 1 & complete_demprimaries_3 == 1

replace correct_demprimaries = 99 if forecast_demprimaries == 99 & demprimariesE == 1 & complete_demprimaries_4 == 1

* Generate dichotomous variable (treat ambiguous forecasts as incorrect)

gen correct_demprimaries_d = correct_demprimaries

replace correct_demprimaries_d = 0 if correct_demprimaries_d == 99
replace correct_demprimaries_d = 1 if correct_demprimaries_d == 1


*********************************
** NATIONAL-LEVEL EXPECTATIONS **
*********************************

* Forecasts

gen bushchances = cna22
gen kerrychances = cna21

recode bushchances (998=.)
recode bushchances (999=.)

recode kerrychances (998=.)
recode kerrychances (999=.)

gen forecast_whole = 1 if bushchances > 50 & bushchances!=.
replace forecast_whole = 1 if kerrychances < 50 & kerrychances!=.
replace forecast_whole = 2 if bushchances < 50 & bushchances!=.
replace forecast_whole = 2 if kerrychances > 50 & kerrychances!=.
replace forecast_whole = 99 if bushchances == 50 & bushchances!=.
replace forecast_whole = 99 if kerrychances == 50 & kerrychances!=.
replace forecast_whole = 99 if cna21 == 998
replace forecast_whole = 99 if cna22 == 998

* Identify correct forecasts

gen correct_whole_d = 0 if forecast_whole!=1 & forecast_whole!=.
replace correct_whole_d = 1 if forecast_whole == 1


**********
** SAVE **
**********

save "us2004_naes.dta", replace


*****************************************
** MAIN ANALYSES: DEMOCRATIC PRIMARIES **
*****************************************

* Regression analysis and percentage of correct and incorrect forecasts (Democratic primaries)

logistic correct_demprimaries_d discussion kerryrating interest_primaries news age i.male education dtime if time > 0
estimates table, star(.05 .01 .001)

tab correct_demprimaries_d if e(sample) == 1


**********************************************
** SUMMARY STATISTICS: DEMOCRATIC PRIMARIES **
**********************************************

label variable correct_whole_d "Presidency winner (DV)"
label variable correct_demprimaries_d "Democratic nominee (DV)"
label variable discussion "Discussion"
label variable pidscale_whole "National PID"
label variable kerryrating "Kerry rating"
label variable interest_president "Interest"
label variable interest_primaries "Interest"
label variable news "News attentiveness"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable dtime "Time of interview"

estpost tabstat correct_demprimaries_d discussion kerryrating interest_primaries news age male education dtime if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "us2004_naes_summary_demprimaries.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2004 Democratic presidential primaries (NAES), national level") replace

eststo clear


******************************************
** MAIN ANALYSES: PRESIDENTIAL ELECTION **
******************************************

* Regression analysis and percentage of correct and incorrect forecasts (national)

logistic correct_whole_d discussion pidscale_whole interest_president news age i.male education time if time > 0
estimates table, star(.05 .01 .001)

tab correct_whole_d if e(sample) == 1


***********************************************
** SUMMARY STATISTICS: PRESIDENTIAL ELECTION **
***********************************************

label variable correct_whole_d "Presidency winner (DV)"
label variable correct_demprimaries_d "emocratic nominee (DV)"
label variable discussion "Discussion"
label variable pidscale_whole "National PID"
label variable kerryrating "Kerry rating"
label variable interest_president "Interest"
label variable interest_primaries "Interest"
label variable news "News attentiveness"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"

estpost tabstat correct_whole_d discussion pidscale_whole interest_president news age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "us2004_naes_summary_national.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2004 American presidential election (NAES), national level") replace

eststo clear

log close